﻿Ext.net.ResourceMgr.init({
    id: "ResourceManager1",
    BLANK_IMAGE_URL: "/extjs/resources/images/default/s-gif/ext.axd",
    aspForm: "Form1",
    theme: "blue",
    icons: ["StopGreen", "StopRed", "ApplicationTileVertical", "Add", "Pencil", "Delete", "Exclamation", "ArrowSwitchBluegreen", "BulletCross", "BulletTick", "Group", "ChartOrganisation", "Accept", "Information", "Disk", "Cancel"]
});
Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.ns("Room");
    Ext.apply(Room, {
        DeleteSelected: function (obj, config) {
            Ext.net.DirectMethod.request("DeleteSelected", Ext.applyIf(config || {},
      {
          params: {
              obj: obj
          }
      }));
        },
        ChangeState: function (obj, NameValue, config) {
            Ext.net.DirectMethod.request("ChangeState", Ext.applyIf(config || {},
      {
          params: {
              obj: obj,
              NameValue: NameValue
          }
      }));
        },
        EditInfo: function (EntityID, config) {
            Ext.net.DirectMethod.request("EditInfo", Ext.applyIf(config || {},
      {
          params: {
              EntityID: EntityID
          }
      }));
        },
        InitClassInfo: function (EntityID, config) {
            Ext.net.DirectMethod.request("InitClassInfo", Ext.applyIf(config || {},
      {
          params: {
              EntityID: EntityID
          }
      }));
        },
        SetClassInfo: function (EntityID, config) {
            Ext.net.DirectMethod.request("SetClassInfo", Ext.applyIf(config || {},
      {
          params: {
              EntityID: EntityID
          }
      }));
        },
        RefreshTree: function (config) {
            Ext.net.DirectMethod.request("RefreshTree", Ext.applyIf(config || {},
      {}));
        }
    });
    this.ClassDS = new Ext.ux.data.PagingStore({
        proxyId: "ClassDS",
        autoLoad: true,
        reader: new Ext.data.JsonReader({
            fields: [{
                name: "EntityID"
            },
      {
          name: "NameCN"
      }],
            idProperty: "EntityID"
        }),
        directEventConfig: {},
        proxy: new Ext.data.PagingMemoryProxy({})
    });
    this.Store1 = new Ext.net.Store({
        proxyId: "Store1",
        autoLoad: {
            params: {
                "start": 0,
                "limit": 20
            }
        },
        proxy: new Ext.net.PageProxy({}),
        reader: new Ext.data.JsonReader({
            fields: [{
                name: "EntityID"
            },
      {
          name: "ClassName"
      },
      {
          name: "Cid"
      },
      {
          name: "CreatedDate"
      },
      {
          name: "Deposit"
      },
      {
          name: "Floor"
      },
      {
          name: "HalfPrice"
      },
      {
          name: "HourPrice"
      },
      {
          name: "IsComputer"
      },
      {
          name: "IsMaQue"
      },
      {
          name: "NightPrice"
      },
      {
          name: "Price"
      },
      {
          name: "Reserve"
      },
      {
          name: "RoomNO"
      },
      {
          name: "Status"
      }],
            idProperty: "EntityID"
        }),
        remoteSort: true,
        sortInfo: {
            field: "EntityID",
            direction: "desc"
        },
        directEventConfig: {},
        listeners: {
            loadexception: {
                fn: function (store, options, response, e) {
                    Ext.MessageBox.alert('系统提示', response.statusText);
                }
            }
        }
    });
    new Ext.net.Viewport({
        id: "ctl02",
        renderTo: "Form1",
        items: [{
            id: "Panel1",
            width: 200,
            items: [{
                id: "TreeContextMenu",
                xtype: "menu",
                items: [{
                    id: "AppendChild",
                    iconCls: "icon-add",
                    text: "添加子类别"
                },
        {
            id: "ctl09",
            xtype: "menuseparator"
        },
        {
            id: "Rename",
            iconCls: "icon-pencil",
            text: "修改"
        },
        {
            id: "Remove",
            iconCls: "icon-delete",
            text: "删除"
        }],
                listeners: {
                    itemclick: {
                        fn: function (menuItem, e) {
                            Kwan.updateTree(ClassTree, menuItem.id);
                        }
                    }
                }
            },
      {
          id: "ClassTree",
          xtype: "nettreepanel",
          autoScroll: true,
          autoHeight: true,
          border: false,
          header: false,
          containerScroll: true,
          enableDD: true,
          loader: new Ext.net.PageTreeLoader({
              preloadChildren: true,
              method: "POST"
          }),
          rootVisible: false,
          mode: "remote",
          nodes: [{
              id: "root",
              checked: false,
              expanded: true,
              text: "Examples",
              nodeType: "async"
          }],
          listeners: {
              render: {
                  delay: 50,
                  fn: function (item) {
                      this.getRootNode().expand(true);
                  }
              },
              click: {
                  fn: function (node, e) {
                      txtFilter.setValue(node.id);
                  }
              },
              contextmenu: {
                  stopEvent: true,
                  fn: Kwan.showMenu
              }
          }
      }],
            layout: "auto",
            tbar: {
                id: "Toolbar1",
                xtype: "toolbar",
                items: [{
                    id: "BtnAddClassInfo",
                    iconCls: "icon-add",
                    text: "添加父类别",
                    tooltip: "子类别可右键以下某项添加",
                    listeners: {
                        click: {
                            fn: function (item, e) {
                                Room.InitClassInfo('');
                            }
                        }
                    }
                },
        {
            id: "ctl04",
            xtype: "tbfill"
        },
        {
            id: "Button1",
            iconCls: "x-tbar-loading",
            text: "刷新",
            listeners: {
                click: {
                    fn: function (item, e) {
                        Room.RefreshTree();
                    }
                }
            }
        }]
            },
            iconCls: "icon-applicationtilevertical"
        },
    {
        id: "GridPanel1",
        columnPlugins: [9, 10, 12],
        xtype: "netgrid",
        columnWidth: 0.8,
        height: 500,
        bbar: {
            id: "PagingToolBar1",
            xtype: "paging",
            items: [{
                id: "ctl31",
                xtype: "label",
                text: "每页显示:"
            },
        {
            id: "ctl33",
            xtype: "nettbspacer",
            width: 10
        },
        {
            id: "ctl35",
            xtype: "combo",
            width: 80,
            value: "20",
            editable: false,
            displayField: "text",
            hiddenName: "ctl35_Value",
            mode: "local",
            queryDelay: 10,
            triggerAction: "all",
            valueField: "value",
            store: new Ext.data.SimpleStore({
                fields: ["text", "value"],
                data: [["10", "10"], ["20", "20"], ["50", "50"], ["100", "100"]]
            }),
            submitValue: true,
            listeners: {
                select: {
                    fn: function (item, record, index) {
                        PagingToolBar1.pageSize = parseInt(this.getValue());
                        PagingToolBar1.doLoad();
                    }
                }
            }
        }],
            displayInfo: true
        },
        tbar: {
            id: "ctl18",
            xtype: "toolbar",
            items: [{
                id: "txtFilter",
                xtype: "hidden",
                listeners: {
                    change: {
                        delay: 30,
                        fn: function (item, newValue, oldValue) {
                            Store1.reload();
                        }
                    }
                }
            },
        {
            id: "txtSearch",
            xtype: "nettrigger",
            emptyText: " 搜索房间号..",
            enableKeyEvents: true,
            triggersConfig: [{
                hideTrigger: true,
                iconCls: "x-form-clear-trigger",
                qtip: "清空"
            },
          {
              iconCls: "x-form-search-trigger",
              qtip: "搜索"
          }],
            listeners: {
                keydown: {
                    fn: function (item, e) {
                        if (!Ext.isEmpty(this.getValue())) {
                            this.triggers[0].show();
                        } else {
                            this.triggers[0].hide();
                        }
                    }
                },
                triggerclick: {
                    fn: function (item, trigger, index, tag, e) {
                        if (index == 1) {
                            Store1.reload();
                        }
                        if (index == 0) {
                            txtSearch.reset();
                            this.triggers[0].hide();
                        }
                    }
                }
            }
        },
        {
            id: "ctl21",
            xtype: "tbfill"
        },
        {
            id: "BtnAddInfo",
            iconCls: "icon-add",
            text: "添加",
            directEvents: {
                click: {
                    fn: function (item, e) {
                        var params = arguments;
                        Ext.net.DirectEvent.confirmRequest({
                            control: this
                        });
                    },
                    delay: 20
                }
            }
        },
        {
            id: "BtnDeleteInfo",
            iconCls: "icon-exclamation",
            text: "批量删除",
            listeners: {
                click: {
                    fn: function (item, e) {
                        Kwan.CheckDelete(GridPanel1.getRowsValues({
                            selectedOnly: true
                        }));
                    }
                }
            }
        },
        {
            id: "ToolbarSeparator2",
            xtype: "tbseparator"
        },
        {
            id: "BtnChangeStatus",
            hidden: true,
            iconCls: "icon-arrowswitchbluegreen",
            menu: {
                id: "Menu1",
                xtype: "menu",
                items: [{
                    id: "Status_0",
                    iconCls: "icon-bulletcross",
                    text: "禁用"
                },
            {
                id: "Status_1",
                iconCls: "icon-bullettick",
                text: "空闲"
            }],
                listeners: {
                    itemclick: {
                        fn: function (menuItem, e) {
                            Room.ChangeAllState(Ext.encode(GridPanel1.getRowsValues({
                                selectedOnly: true
                            })), menuItem.id);
                        }
                    }
                }
            },
            text: "更改状态"
        }]
        },
        frame: true,
        header: false,
        autoExpandColumn: "RoomNO",
        loadMask: {
            showMask: true
        },
        saveMask: {
            showMask: true
        },
        sm: this.ctl16 = new Ext.grid.CheckboxSelectionModel({
            proxyId: "ctl16"
        }),
        store: Store1,
        stripeRows: true,
        trackMouseOver: true,
        selectionSavingBuffer: 10,
        memoryIDField: "EntityID",
        cm: this.ctl17 = new Ext.grid.ColumnModel({
            proxyId: "ctl17",
            columns: [ctl16, new Ext.grid.RowNumberer({}), {
                dataIndex: "RoomNO",
                header: "房号",
                id: "RoomNO",
                width: 80
            },
        {
            dataIndex: "ClassName",
            header: "房型"
        },
        {
            dataIndex: "Price",
            header: "价格"
        },
        {
            dataIndex: "HalfPrice",
            header: "半天价",
            width: 80
        },
        {
            dataIndex: "HourPrice",
            header: "钟点价",
            width: 80
        },
        {
            dataIndex: "NightPrice",
            header: "夜房价",
            width: 80
        },
        {
            dataIndex: "Reserve",
            header: "最低价",
            width: 80
        },
        new Ext.net.CommandColumn({
            dataIndex: "IsComputer",
            header: "电脑",
            hideable: false,
            width: 40,
            commands: [{
                xtype: "tbbutton",
                command: "IsComputer"
            }],
            prepareToolbar: Kwan.prepareBit
        }), new Ext.net.CommandColumn({
            dataIndex: "IsMaQue",
            header: "麻雀",
            hideable: false,
            width: 40,
            commands: [{
                xtype: "tbbutton",
                command: "IsMaQue"
            }],
            prepareToolbar: Kwan.prepareBit
        }), {
            dataIndex: "Status",
            header: "房态",
            renderer: Kwan.prepareRoomStatus,
            width: 80
        },
        new Ext.net.CommandColumn({
            hideable: false,
            width: 55,
            commands: [{
                xtype: "tbbutton",
                command: "Delete",
                iconCls: "icon-delete",
                text: "删除"
            }]
        })]
        }),
        listeners: {
            rowdblclick: {
                fn: function (item, rowIndex, e) {
                    Kwan.CellCommand(this, this.store.getAt(rowIndex), 'Edit', rowIndex)
                }
            },
            command: {
                fn: function (command, record, rowIndex, colIndex) {
                    Kwan.CellCommand(this, record, command, rowIndex)
                }
            }
        }
    }],
        layout: "netcolumn"
    });
    new Ext.Window({
        id: "EditWindow",
        labelWidth: 70,
        hidden: true,
        renderTo: Ext.get("Form1"),
        height: 290,
        width: 650,
        items: {
            id: "TabPanel1",
            xtype: "tabpanel",
            items: {
                id: "RoomForm",
                xtype: "form",
                labelAlign: "right",
                labelWidth: 70,
                monitorResize: true,
                items: [{
                    id: "txtID",
                    xtype: "hidden"
                },
        {
            id: "ctl41",
            xtype: "container",
            anchor: "99%",
            height: 180,
            items: [{
                id: "ctl42",
                xtype: "container",
                columnWidth: 0.5,
                items: [{
                    id: "txtCid",
                    xtype: "netdropdown",
                    anchor: "98%",
                    fieldLabel: "房型",
                    allowBlank: false,
                    editable: false,
                    triggerClass: "x-form-search-trigger",
                    mode: "valuetext",
                    component: {
                        id: "TreePanel1",
                        xtype: "nettreepanel",
                        autoScroll: true,
                        height: 300,
                        iconCls: "icon-accept",
                        shadow: false,
                        containerScroll: true,
                        enableDD: true,
                        loader: new Ext.net.PageTreeLoader({
                            preloadChildren: true,
                            method: "POST"
                        }),
                        rootVisible: false,
                        useArrows: true,
                        nodes: [{
                            id: "root",
                            checked: false,
                            expanded: true,
                            text: "Examples",
                            nodeType: "async"
                        }],
                        listeners: {
                            click: {
                                fn: function (node, e) {
                                    this.dropDownField.setValue(node.id, node.attributes.text, true);
                                }
                            }
                        }
                    },
                    listeners: {
                        expand: {
                            delay: 10,
                            single: true,
                            fn: function (item) {
                                this.component.getRootNode().expand(true);
                            }
                        }
                    }
                },
            {
                id: "txtRoomNO",
                xtype: "textfield",
                anchor: "98%",
                fieldLabel: "房间号",
                allowBlank: false
            },
            {
                id: "txtFloor",
                xtype: "textfield",
                anchor: "98%",
                fieldLabel: "楼层"
            },
            {
                id: "txtStatus",
                xtype: "combo",
                anchor: "80%",
                fieldLabel: "状态",
                value: "1",
                allowBlank: false,
                emptyText: "请选择...",
                editable: false,
                displayField: "text",
                hiddenName: "txtStatus_Value",
                mode: "local",
                queryDelay: 10,
                triggerAction: "all",
                valueField: "value",
                store: new Ext.data.SimpleStore({
                    fields: ["text", "value"],
                    data: [["空净房", "0"], ["维修房", "3"]]
                }),
                submitValue: true
            },
            {
                id: "ctl48",
                xtype: "checkboxgroup",
                fieldLabel: "选项",
                itemCls: " x-form-cb-label-nowrap",
                items: [{
                    id: "txtIsComputer",
                    xtype: "checkbox",
                    boxLabel: "有电脑",
                    inputValue: "txtIsComputer"
                },
              {
                  id: "txtIsMaQue",
                  xtype: "checkbox",
                  boxLabel: "有麻雀",
                  inputValue: "txtIsMaQue"
              }]
            },
            {
                id: "ctl52",
                xtype: "label",
                html: "<font color='red'>系统优先选择房间价格来发放房卡。<BR/>当此房的 [价格] 及 [最低价] 与房型定价不同时才录入！</font>",
                iconCls: "icon-information"
            }],
                layout: "form"
            },
          {
              id: "ctl55",
              xtype: "container",
              columnWidth: 0.5,
              items: [{
                  id: "txtPrice",
                  xtype: "numberfield",
                  anchor: "98%",
                  fieldLabel: "价格",
                  decimalSeparator: "."
              },
            {
                id: "txtReserve",
                xtype: "numberfield",
                anchor: "98%",
                fieldLabel: "最低价",
                decimalSeparator: "."
            },
            {
                id: "txtHalfPrice",
                xtype: "numberfield",
                anchor: "98%",
                fieldLabel: "半天价",
                decimalSeparator: "."
            },
            {
                id: "txtHourPrice",
                xtype: "numberfield",
                anchor: "98%",
                fieldLabel: "钟点价",
                decimalSeparator: "."
            },
            {
                id: "txtNightPrice",
                xtype: "numberfield",
                anchor: "98%",
                fieldLabel: "夜房价",
                decimalSeparator: "."
            },
            {
                id: "txtDeposit",
                xtype: "numberfield",
                anchor: "98%",
                fieldLabel: "默认押金",
                decimalSeparator: "."
            },
            {
                id: "txtCreatedDate",
                xtype: "datefield",
                anchor: "70%",
                disabled: true,
                fieldLabel: "创建日期",
                hidden: true,
                readOnly: true,
                format: "Y-m-d H:i:s"
            }],
              layout: "form"
          }],
            layout: "netcolumn"
        }],
                iconCls: "icon-chartorganisation",
                padding: 10,
                title: "基本信息",
                monitorValid: true,
                renderFormElement: false,
                url: "/Ext/Room/Default.aspx",
                listeners: {
                    clientvalidation: {
                        fn: function (item, valid) {
                            SaveButton.setDisabled(!valid);
                        }
                    }
                }
            },
            border: false,
            activeTab: 0,
            deferredRender: false
        },
        layout: "fit",
        buttons: [{
            id: "SaveButton",
            iconCls: "icon-disk",
            text: "保存",
            directEvents: {
                click: {
                    fn: function (item, e) {
                        var params = arguments;
                        Ext.net.DirectEvent.confirmRequest({
                            eventMask: {
                                showMask: true,
                                target: "customtarget",
                                customTarget: EditWindow.body
                            },
                            userFailure: function (response, result, el, type, action, extraParams, o) {
                                Ext.MessageBox.alert('系统提示', response.statusText);
                            },
                            control: this
                        });
                    },
                    delay: 20
                }
            }
        },
    {
        id: "CancelButton",
        iconCls: "icon-cancel",
        text: "返回",
        listeners: {
            click: {
                fn: function (item, e) {
                    EditWindow.hide(null);
                }
            }
        }
    }],
        collapsible: true,
        iconCls: "icon-group",
        title: "编辑数据",
        maximizable: true,
        modal: true
    });
    new Ext.Window({
        id: "ClassWindow",
        labelWidth: 70,
        hidden: true,
        renderTo: Ext.get("Form1"),
        height: 320,
        width: 450,
        items: {
            id: "ClassForm",
            xtype: "form",
            columnWidth: 0.6,
            labelAlign: "right",
            labelWidth: 70,
            monitorResize: true,
            items: [{
                id: "txtClassID",
                xtype: "hidden"
            },
      {
          id: "txtClassNameCN",
          xtype: "textfield",
          anchor: "90%",
          fieldLabel: "名称",
          allowBlank: false
      },
      {
          id: "txtClassNameEN",
          xtype: "textfield",
          anchor: "90%",
          fieldLabel: "代码"
      },
      {
          id: "txtClassPrice",
          xtype: "numberfield",
          anchor: "90%",
          fieldLabel: "价格",
          decimalSeparator: "."
      },
      {
          id: "txtClassHalfPrice",
          xtype: "numberfield",
          anchor: "90%",
          fieldLabel: "半天价",
          decimalSeparator: "."
      },
      {
          id: "txtClassHourPrice",
          xtype: "numberfield",
          anchor: "90%",
          fieldLabel: "钟点价",
          decimalSeparator: "."
      },
      {
          id: "txtClassNightPrice",
          xtype: "numberfield",
          anchor: "90%",
          fieldLabel: "夜房价",
          decimalSeparator: "."
      },
      {
          id: "txtClassReserve",
          xtype: "numberfield",
          anchor: "90%",
          fieldLabel: "最低价",
          decimalSeparator: "."
      },
      {
          id: "txtClassPid",
          xtype: "combo",
          anchor: "60%",
          fieldLabel: "类别",
          hidden: true,
          emptyText: "请选择...",
          editable: false,
          displayField: "NameCN",
          hiddenName: "txtClassPid_Value",
          triggerAction: "all",
          valueField: "EntityID",
          store: ClassDS,
          submitValue: true
      },
      {
          id: "txtClassSort",
          xtype: "textfield",
          anchor: "90%",
          fieldLabel: "排序"
      },
      {
          id: "ctl81",
          xtype: "label",
          html: "<font color='red'>必须输入 [价格] 及 [最低价] ，否则可能会造成无法入住！</font>",
          iconCls: "icon-information"
      }],
            buttons: [{
                id: "ClassSaveButton",
                iconCls: "icon-disk",
                text: "保存",
                directEvents: {
                    click: {
                        fn: function (item, e) {
                            var params = arguments;
                            Ext.net.DirectEvent.confirmRequest({
                                eventMask: {
                                    showMask: true,
                                    target: "customtarget",
                                    customTarget: ClassWindow.body
                                },
                                userFailure: function (response, result, el, type, action, extraParams, o) {
                                    Ext.MessageBox.alert('系统提示', response.statusText);
                                },
                                control: this
                            });
                        },
                        delay: 20
                    }
                }
            },
      {
          id: "BtnClassCancel",
          iconCls: "icon-cancel",
          text: "返回",
          listeners: {
              click: {
                  fn: function (item, e) {
                      ClassWindow.hide(null);
                  }
              }
          }
      }],
            iconCls: "icon-chartorganisation",
            padding: 5,
            monitorValid: true,
            renderFormElement: false,
            url: "/Ext/Room/Default.aspx",
            listeners: {
                clientvalidation: {
                    fn: function (item, valid) {
                        ClassSaveButton.setDisabled(!valid);
                    }
                }
            }
        },
        layout: "netcolumn",
        collapsible: true,
        iconCls: "icon-group",
        title: "编辑数据",
        maximizable: true,
        modal: true
    });
});